﻿
namespace Red.Core
{
    /// <summary>
    ///     Intended as a result of an operation that may fail - if so, carries an error message.
    /// </summary>
    public struct Result
    {
        public string Message { get; private set; }

        public static Result Failed( string message )
        {
            return new Result() { Message = message };
        }

        public static Result Ok = new Result();

        public static bool operator true( Result f ) { return f.Message == null; }

        public static bool operator false( Result f ) { return f.Message != null; }

        public static bool operator !( Result f ) { return f.Message != null; }
    }

    /// <summary>
    ///     Intended as a result of an operation that may fail - if so, carries an error message. 
    ///     Otherwise, carries the operation result as Value.
    /// </summary>
    public struct Result<T>
    {
        public T Value { get; private set; }

        public string Message { get; private set; }

        public static Result<T> Failed( string message )
        {
            return new Result<T>(){ Message = message };
        }

        public static Result<T> Ok( T value )
        {
            return new Result<T>() { Value = value };
        }

        public static bool operator true( Result<T> f ) { return f.Message == null; }

        public static bool operator false( Result<T> f ) { return f.Message != null; }

        public static bool operator !( Result<T> f ) { return f.Message != null; }
    }
}
